package com.cjc.myadapter;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.cjc.myadapter.bean.Bean;
import com.cjc.mybase.activity.BaseActivity;
import com.cjc.mybase.adapter.CommonAdapter;
import com.cjc.mybase.adapter.ViewHolder;
/**
 *****************************************************
 * <hr>
 * <dt><span class="strong">类功能简介:</span></dt>
 * <dd>Coffee</dd>
 * <dt><span class="strong">创建时间:</span></dt>
 * <dd>2015-4-20 上午11:07:24</dd>
 * <dt><span class="strong">公司:</span></dt>
 * <dd>CorpIt</dd>
 * @author aa1000777 - Email:aa1000777@qq.com
 *****************************************************
 */
public class MainActivity extends BaseActivity {
	private CommonAdapter<Bean> adapter;
	private List<Bean> data;
	private ListView listView;

	@Override
	protected void initView(Bundle savedInstanceState) {
		// XXX Auto-generated method stub
		super.initView(savedInstanceState);
		System.out.println("-------------MainActivity----------------");
		setContentView(R.layout.activity_main);
		listView = (ListView) findViewById(R.id.mLV_main_activity_list);
	}


	@Override
	protected void initData(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.initData(savedInstanceState);
		data = new ArrayList<Bean>();
		for (int i = 0; i < 999; i++) {
			Bean bean = new Bean();
			bean.Id = i;
			bean.Image = R.drawable.ic_launcher;
			bean.Title = "标题" + i;
			bean.Content = "内容" + i;
			data.add(bean);
		}
		adapter = new CommonAdapter<Bean>(context, data, R.layout.activity_main_list_item) {

			@Override
			public void convert(ViewHolder helper, Bean item) {
				// TODO Auto-generated method stub
				helper.setText(R.id.mTV_activity_main_list_item_title, item.Title);
				helper.setText(R.id.mTV_activity_main_list_item_content, item.Content);
				helper.setImageResource(R.id.mIV_activity_main_list_item_image, item.Image);
			}
		};
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				// TODO Auto-generated method stub
				System.out.println("点击了：" + data.get(position).Title);
			}
		});
	}

}
